home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / mach / Machrules < prev    next >
Encoding:
Text File  |  1994-07-19  |  8.1 KB  |  220 lines

  1. # Rules for MiG interfaces that want to go into the C library.
  2.  
  3. # Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
  4. # This file is part of the GNU C Library.
  5.  
  6. # The GNU C Library is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU Library General Public License
  8. # as published by the Free Software Foundation; either version 2 of
  9. # the License, or (at your option) any later version.
  10.  
  11. # The GNU C Library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. # Library General Public License for more details.
  15.  
  16. # You should have received a copy of the GNU Library General Public
  17. # License along with the GNU C Library; see the file COPYING.LIB.  If
  18. # not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  19. # Cambridge, MA 02139, USA.
  20.  
  21. # Makefiles may define these variable before including this file:
  22. #    user-interfaces        Names of interfaces to put user stubs in for.
  23. #    server-interfaces    Names of interfaces to put server stubs in for.
  24. #    interface-library    Name of interface library to build and install.
  25. # This file sets:
  26. #    interface-headers    Names of generated interface header files.
  27. #    interface-routines    Names of generated interface routines.
  28. # All user stubs are put in individual files, prefixed with RPC_ (and the
  29. # function names prefixed with __), and a symbol-alias to the un-__'d form
  30. # generated; header for both is put in foo.h.  Server interfaces are
  31. # written to foo_server.c and foo_server.h; the server functions are called
  32. # _S_rpcname.
  33.  
  34. # Includers can also add to or modify `migdefines' to set MiG flags.
  35.  
  36. all:
  37.  
  38. # Make sure no value comes from the environment, since we append to it.
  39. # This is done also in ../Rules, but we append to the value before
  40. # including Rules, which changes the origin.
  41. ifneq    "$(findstring env,$(origin generated))" ""
  42. generated :=
  43. endif
  44.  
  45.  
  46. include ../Makeconfig
  47.  
  48. ifndef MIG
  49. MIG = mig
  50. endif
  51. MIGFLAGS = -DMACH_IPC_COMPAT=0 -DSTANDALONE -DTypeCheck=0 \
  52.        $(+includes) $(migdefines) -subrprefix __
  53.  
  54. .SUFFIXES: .defs    # Just to set specified_rule_matched.
  55.  
  56. define nl    # This is needed by *.ir.
  57.  
  58.  
  59. endef
  60. ifdef user-interfaces
  61. *.ir := $(addprefix $(objpfx),$(foreach if,$(user-interfaces),$(if).ir))
  62. ifndef inhibit_interface_rules
  63. include $(*.ir)
  64. endif
  65. ifneq "$(*.ir)" "$(wildcard $(*.ir))"
  66. # If any .ir file is missing, we will be unable to make all the deps.
  67. no_deps=t
  68. endif
  69. generated += $(*.ir:$(objpfx)%=%)
  70. endif
  71.  
  72.  
  73. # %.ir defines a variable `%-calls', which lists the RPCs defined by
  74. # %.defs, and a rule to build $(%-calls:%=RPC_$(%-userprefix)%.c) from
  75. # %.defs, where $(%-userprefix) is the user prefix given in %.defs.  We use
  76. # the kludgificacious method of defining a pattern rule to build files
  77. # matching patterns we are pretty damn sure will only match the particular
  78. # files we have in mind.  To be so damn sure, we use the silly names
  79. # RPC_*.c and the pattern R%C_*.c because using __*.c and _%*.c (or any
  80. # other useful pattern) causes the rule for `host_info' to also match
  81. # `xxx_host_info', and analogous lossage.
  82. #
  83. # While we're at it, we figure out the imports used by %.defs and give them
  84. # as dependencies of the object files for the generated RPC_*.c files.
  85. #
  86. # Depend on %.h just so they will be built from %.uh in the
  87. # makefile-rebuilding run which builds %.ir; otherwise, %.uh is built as an
  88. # intermediate in order to make %.ir and then removed before re-exec, when
  89. # %.uh is built all over again to build %.h.
  90. $(objpfx)%.ir: $(objpfx)%.uh $(objpfx)%.h
  91.     (awk "NF == 4 && (\$$2 == \"Routine\" || \$$2 == \"SimpleRoutine\")\
  92.             { printf \"$*-calls += %s\\n\", \$$3 }    \
  93.           /^#include/ { printf \"$*-imports += %s\\n\", \$$2 }" $<    ;\
  94.      echo '$$($*-calls:%=$$(objpfx)R\%C_%.c): $$(objpfx)$*.ustamp ;';\
  95.      echo '$$($*-calls:%=$$(objpfx)RPC_%.o): $$($*-imports:<%>=%)'    ;\
  96.     ) > $@-new
  97.     mv $@-new $@
  98. vpath Machrules ../mach    # Find ourselves.
  99.  
  100. ifndef transform-user-stub-output
  101. transform-user-stub-output = tmp
  102. endif
  103.  
  104. # Not an implicit rule so the stamps are never removed as intermediates!
  105. $(patsubst %,$(objpfx)%.ustamp,$(user-interfaces)): $(objpfx)%.ustamp: %.defs
  106.     $(MIG) $< $(MIGFLAGS) $(user-MIGFLAGS) \
  107.            -prefix __ -i $(objpfx)tmp_ \
  108.            -server /dev/null -user /dev/null -header /dev/null
  109.     for call in $($*-calls); do \
  110.       $(transform-user-stub) \
  111.       ../move-if-change $(objpfx)$(transform-user-stub-output)_$${call}.c \
  112.                 $(objpfx)RPC_$${call}.c; \
  113.     done
  114.     touch $@
  115.  
  116. # Look for the server stub files where they will be written.
  117. vpath %_server.c $(addprefix $(objpfx),$(sort $(dir $(server-interfaces))))
  118.  
  119. # Build the server stubs in $(objdir).
  120. $(objpfx)%_server.c $(objpfx)%_server.h: %.defs
  121.     $(MIG) $< $(MIGFLAGS) $(server-MIGFLAGS) \
  122.            -prefix _S_ \
  123.            -user /dev/null -header /dev/null \
  124.            -server $(@:.h=.c) -sheader $(@:.c=.h)
  125.  
  126. # To get header files that declare both the straight and __ functions,
  127. # we generate two files and paste them together.
  128. $(objpfx)%.uh: %.defs; $(mig.uh)
  129. define mig.uh
  130. $(make-target-directory)
  131. $(MIG) $< $(MIGFLAGS) \
  132.        -header $@ -server /dev/null -user /dev/null
  133. endef
  134. $(objpfx)%.__h: %.defs; $(mig.__h)
  135. define mig.__h
  136. $(make-target-directory)
  137. $(MIG) $< $(MIGFLAGS) -prefix __ \
  138.        -header $@ -server /dev/null -user /dev/null
  139. endef
  140.  
  141. $(objpfx)%.h: $(objpfx)%.__h $(objpfx)%.uh
  142. # The last line of foo.__h is "#endif _foo_user_".
  143. # The first two lines of foo.uh are "#ifndef _foo_user_"/"#define _foo_user_".
  144.     (sed -e '$$d' $<; sed -e '1,2d' $(word 2,$^)) > $@-new
  145.     mv $@-new $@
  146.  
  147. if-calls.c := $(strip $(foreach if,$(user-interfaces),$($(if)-calls:%=%.c)))
  148. ifdef if-calls.c
  149. $(addprefix $(objpfx),$(if-calls.c)): $(objpfx)%.c: # Machrules
  150.     (echo '#include <gnu-stabs.h>'; \
  151.      echo 'symbol_alias (__$*, $*);') > $@-new
  152.     mv $@-new $@
  153. endif
  154.  
  155. interface-routines := $(foreach if,$(user-interfaces),            \
  156.                 $($(if)-calls)                \
  157.                 $(addprefix RPC_,$($(if)-calls)))    \
  158.               $(server-interfaces:%=%_server)
  159. interface-headers := $(user-interfaces:%=%.h) \
  160.              $(server-interfaces:%=%_server.h)
  161.  
  162. # Remove the generated user stub source and header files,
  163. # and don't distribute them.
  164. mach-generated = $(interface-routines:%=%.c) \
  165.          $(foreach h,$(interface-headers:%.h=%),$h.h $h.uh $h.__h)
  166. generated += $(mach-generated)
  167.  
  168. # These are needed to generate the dependencies.
  169. before-compile += $(interface-headers:%=$(objpfx)%)
  170.  
  171. # Don't let these be intermediate files and get removed.
  172. $(foreach h,$(interface-headers:%.h=$(objpfx)%),$h.h $h.__h $h.uh) :
  173. $(interface-routines:%=$(objpfx)%.c) :
  174.  
  175. # Convenient target to generate all the headers.
  176. .PHONY: interface-headers
  177. interface-headers: $(interface-headers)
  178.  
  179. # Don't automatically generate dependencies for the sources we generate.
  180. # There are likely to be a whole lot of them, and we know their
  181. # dependencies ahead of time anyway because they're boilerplate.
  182. omit-deps += $(interface-routines)
  183.  
  184. # Specify the static dependencies of the generated files.
  185. $(foreach if,$(user-interfaces),$($(if)-calls:%=$(objpfx)RPC_%.o))): \
  186.     mach/boolean.h mach/kern_return.h mach/message.h mach/notify.h \
  187.     mach/mach_types.h mach/mig_errors.h mach/mig_support.h mach/msg_type.h
  188. $(foreach if,$(user-interfaces),$($(if)-calls:%=$(objpfx)%.o)): ../gnu-stabs.h
  189. $(server-interfaces:%=$(objpfx)%.o): \
  190.     mach/boolean.h mach/kern_return.h mach/message.h mach/mig_errors.h \
  191.     mach/mig_support.h mach/std_types.h
  192. # The MiG-generated sources also depend on the imports in their .defs files.
  193. # These dependencies are generated into the .ir files above.
  194.  
  195. # If defined, $(interface-library) is `libNAME.a'.  It is to be a library
  196. # containing all the MiG-generated functions for the specified interfaces.
  197.  
  198. ifdef interface-library
  199.  
  200. $(interface-library)-objs := $(interface-routines:%=%.o)
  201.  
  202. install-lib += $(interface-library)
  203. extra-objs += $($(interface-library)-objs)
  204.  
  205. $(objpfx)$(interface-library): $(addprefix $(objpfx),\
  206.                        $($(interface-library)-objs))
  207. ifdef objdir
  208.     cd $(objdir); $(AR) cru$(verbose) $(@:$(objpfx)%=%) $(^:$(objpfx)%=%)
  209. else
  210.     $(AR) cru$(verbose) $@ $^
  211. endif
  212.     $(RANLIB) $@
  213.  
  214. lib-noranlib: $(objpfx)$(interface-library)
  215.  
  216. mostlyclean:
  217.     -rm -f $(objpfx)$(interface-library)
  218.  
  219. endif
  220.